package nl.boektrust.btsoep.shared.model;

public enum ISBNReferenceType {
	/**
	 * Enum to specify ISBN References. The types are used as specified in ONIX 2.1 codelist 51.
	 */
	UNDEFINED,REPLACEDBY, REPLACES, RELATEDTO,ALTERNATIVE_FORMAT;
	
	public static String stringValue(ISBNReferenceType t) {
		String value = new String("");
		if (t == null) return value;
		switch (t) {
		case UNDEFINED: value="onbekend"; break;
		case RELATEDTO: value = "gerelateerd aan"; break;
		case REPLACES: value = "vervangt"; break;
		case REPLACEDBY: value = "vervangen door"; break;
		case ALTERNATIVE_FORMAT: value = "alternatief formaat"; break;

		}
		return value;
		
	}
	
	public static ISBNReferenceType parseStringIntoISBNReferenceType(String s) {
		for (ISBNReferenceType t : ISBNReferenceType.values()) {
			if (ISBNReferenceType.stringValue(t).equals(s) == true) return t;
		}
		return UNDEFINED;
	}
	
	public static int intValueForOnix(ISBNReferenceType t) {
		int value = 0;
		if (t == null) {
			System.err.println("ISBNReferenceType.intValueForOnix() was called with a null argument");
			return 00;
		}
		switch (t) {
		case UNDEFINED: value = -1; break;
		case RELATEDTO: value = 0; break;
		case REPLACES: value = 3; break;
		case REPLACEDBY: value = 5; break;
		case ALTERNATIVE_FORMAT: value = 6; break;
		}
		return value;
		
	}
}
